package collectors.people.util;

import java.net.URLEncoder;
import java.util.Map.Entry;
import java.util.Set;

import services.CollectorService;
import services.CollectorService.Services;

import com.typesafe.config.ConfigValue;

public class Config {

	private static Config instance; 
	
	public String fbkey;
	public String fbsecret;
	public String fbaccess;
	public String fblogin;
	public String fboauth;
	
	public String userfbquery;

	public String youredirect;

	
	private Config() {}
	
	public static Config get() {
		return instance;
	}
	
	public static void readConfig(Set<Entry<String,ConfigValue>> entries) throws Exception {
		instance = new Config();
		
		String loginTemplate = "";
		
		for (Entry<String,ConfigValue> entry : entries) {
			String key = entry.getKey();
			ConfigValue val = entry.getValue();
			String rawVal = val.unwrapped().toString();
			
			if (key.equals("facebook.key")) {
				instance.fbkey = rawVal;
			} else if (key.equals("facebook.secret")) {
				instance.fbsecret = rawVal;
			} else if (key.equals("facebook.access")) {
				instance.fbaccess = rawVal;
			} else if (key.equals("facebook.query.user")) {
				instance.userfbquery = rawVal;
			} else if (key.equals("facebook.login")) {
				loginTemplate = rawVal;
			} else if (key.equals("facebook.oauth")) {
				instance.fboauth = rawVal;
			} else if (key.equals("you.redirect")) {
				instance.youredirect = rawVal;
			}
		}
		
		instance.fblogin = loginTemplate.replace("$ID$", instance.fbkey);
	}
}
